import { MergeConfigItem } from '@/components/FormPro/props';
import { getEditOrDetailConfig } from '@/components/FormPro/util';

export const getFormFileds = () => {
  const formBaseList: MergeConfigItem[] = [
    {
      label: '现有密码',
      filed: 'password',
      props: {
        component: {
          placeholder: '请输入 现有密码',
        },
        formItem: {
          rules: [
            { required: true, trigger: 'change', message: '请输入 现有密码' },
          ],
        },
      },
      component: 'a-input-password',
    },
    {
      label: '新密码',
      filed: 'new_password',
      props: {
        component: {
          placeholder: '请输入 新密码',
        },
        formItem: {
          rules: [
            { required: true, trigger: 'change', message: '请输入 新密码' },
          ],
        },
      },
      component: 'a-input-password',
    },
    {
      label: '再次输入新密码',
      filed: 'againnew_password',
      props: {
        component: {
          placeholder: '请再次输入新密码',
        },
        formItem: ({ formModel }: any) => {
          const validator = (val: any, cb: any) => {
            if (!formModel?.againnew_password) {
              cb('请再次输入新密码');
            }
            if (formModel.againnew_password !== formModel.new_password) {
              cb('两次密码不一致');
            } else {
              cb();
            }
          };
          return {
            rules: [{ required: true, validator }],
          };
        },
      },
      component: 'a-input-password',
    },
  ];

  return getEditOrDetailConfig(formBaseList, 'edit');
};
